package com.cym.utils;

import net.sourceforge.pinyin4j.PinyinHelper;

public class Tools {

	public static void main(String[] args) {
		buildCreate();
	}

	public static void buildCreate() {
		String name = "ods_sgzw_fr_txlfl_addressbook_code";

		String sql = "CREATE TABLE IF NOT EXISTS " + name + " (\n";
		String commentSql = "";

		String str = "主键	ZJ	bigint";

		String[] strs = str.split("\n");
		for (String s : strs) {

			String[] lines = s.trim().split("\\s+");

			String comment = lines[0];
			String column = lines[1];
			String type = lines[2];

			sql += "  " + column + " " + type + ",\n";

			commentSql += "COMMENT ON COLUMN " + name + "." + column + " IS '" + comment + "';\n";
		}
		sql = sql.substring(0, sql.length() - 2);
		sql += "\n);\n" + commentSql;

		System.err.println(sql);
	}

	public static void buildColumn() {

		String str = "主键";

		String[] strs = str.split("\n");

		for (String s : strs) {
			System.err.println(getFirstLetters(s));
		}

	}

	/**
	 * 获取中文字符串的拼音首字母
	 *
	 * @param chinese 中文字符串
	 * @return 拼音首字母（大写）
	 */
	public static String getFirstLetters(String chinese) {
		StringBuilder result = new StringBuilder();
		for (char c : chinese.toCharArray()) {
			// 判断是否是汉字
			if (Character.toString(c).matches("[\\u4E00-\\u9FA5]+")) {
				// 获取拼音数组（多音字可能会返回多个拼音）
				String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c);
				if (pinyinArray != null && pinyinArray.length > 0) {
					// 取第一个拼音的首字母，并转为大写
					result.append(pinyinArray[0].charAt(0));
				}
			} else {
				// 非汉字直接拼接
				result.append(c);
			}
		}
		return result.toString().toUpperCase();
	}
	
	
	
	
}
